package com.yanqu.road.server.cmd.activity.zhenhuan;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityWorshipModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_QUERY_ACTIVITY_USER_BASE_INFO, desc = "查询活动中玩家的基本信息")
public class QueryActivityUserBaseInfoCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ZhenHuanProto.QueryActivityUserBaseInfoReqMsg reqMsg = ZhenHuanProto.QueryActivityUserBaseInfoReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        int size = reqMsg.getUserIdsList().size();
        if (size > 100) { //一次最多拉100个
            ret = GameErrorCode.E_ERROR_DATA;
            return;
        }

        if (activityId != 0) {
            ActivityInfo openActivityInfo = ActivityMgr.getOpenActivityInfo(activityId);
            if (openActivityInfo == null) {
                ret = GameErrorCode.E_ACTIVITY_NOT_OPEN;
                return;
            }
            player.sendPacket(CrossProtocol.C_CROSS_QUERY_ACTIVITY_USER_BASE_INFO, reqMsg.toBuilder());
        } else {
            //活动id为0, 去游戏服拉
            //伟杰做了通用的，这里不写了
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret > 0) {
            player.sendPacket(ClientProtocol.U_QUERY_ACTIVITY_USER_BASE_INFO, ZhenHuanProto.QueryActivityUserBaseInfoRespMsg.newBuilder().setRet(ret));
        }
    }

}
